package cn.sdormitory.controller;

import cn.sdormitory.common.annotation.SysLog;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.enums.BusinessType;
import cn.sdormitory.service.AppUserService;
import cn.sdormitory.sys.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: lx
 * @date: 2023/9/8 14:52
 * @description:
 */
@RestController
@RequestMapping("/app/user")
@Api("用户接口")
public class AppUserController {

    @Autowired
    AppUserService appUserService;

    @ApiOperation("listAll => 获取所有用户列表")
    @GetMapping(value = "/listAllUser")
    public CommonResult<List<SysUser>> listAllUser() {
        List<SysUser> users = appUserService.listAllUser();
        return CommonResult.success(users);
    }

    @ApiOperation("listAll => 获取所有有效班主任列表")
    @GetMapping(value = "/getAllClassTeacherList")
    public CommonResult<List<SysUser>> getAllClassTeacherList() {
        List<SysUser> users = appUserService.getAllClassTeacherList();
        return CommonResult.success(users);
    }

    @ApiOperation("listAll => 获取所有有效教员列表")
    @GetMapping(value = "/getAllCourseInstructorList")
    public CommonResult<List<SysUser>> getCourseInstructorList() {
        List<SysUser> users = appUserService.getAllCourseInstructorList();
        return CommonResult.success(users);
    }

    @ApiOperation(value = "resetPwd => 修改密码", notes = "重置密码")
    @PutMapping(value = "/resetPwd")
    public CommonResult<Integer> resetPwd(@RequestBody Map<String,String> map) {
        // 更新密码
        int result = appUserService.resetPwd(map);
        if (result > 0) {
            return CommonResult.success(result);
        }else if( result == -1){
            return CommonResult.failed("旧密码错误!!!");
        }else if(result == -2){
            return CommonResult.failed("新密码两次输入不一致!!!");
        }
        return CommonResult.failed();

    }
}
